package com.hengpeng.itfints.controller.repayment;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.hengpeng.itfinbase.persist.ReceivePlan;
import com.hengpeng.itfinbase.persist.RepaymentPlan;
import com.hengpeng.itfinbase.persist.UserInfo;
import com.hengpeng.itfints.controller.BaseController;
/**
 * <pre>
 * 还款控制器
 * </pre>
 * @author weiyuan
 * @version 1.0, 2015年6月3日
 */
@Controller
@RequestMapping("/repayment")
public class RepaymentController extends BaseController
{
	/**
	 * <pre>
	 * 标的还款列表
	 * </pre>
	 * @param map
	 * @param request
	 * @param status 还款计划状态
	 * @param beginDate 还款截止时间查询开始时间
	 * @param endDate 还款截止时间查询结束时间
	 * @param borrowUserName 借款人姓名
	 * @return
	 */
	@RequestMapping(value = "/myRepayMentList")
	public String myRepayMentList(ModelMap map, HttpServletRequest request, String borrowInfoId)
	{
		List<RepaymentPlan> result = serviceFactory.getRepaymentService().getRepaymentPlans(Long.parseLong(borrowInfoId), null, null);
		map.put("repaymentList", result);
		return "/page/account/borrowinfo/myRepayMentList.jsp";
	}
	/**
	 * <pre>
	 * 收款列表
	 * </pre>
	 * @param map
	 * @param request
	 * @param status 还款计划状态
	 * @param beginDate 还款截止时间查询开始时间
	 * @param endDate 还款截止时间查询结束时间
	 * @param borrowUserName 借款人姓名
	 * @return
	 */
	@RequestMapping(value = "/myReceivePlanList")
	public String myReceivePlanList(ModelMap map, HttpServletRequest request , String borrowInfoId, String investUserId)
	{
		List<ReceivePlan> result = serviceFactory.getRepaymentService().getReceivePlans(Long.parseLong(borrowInfoId),
				Long.parseLong(investUserId), null, null);
		map.put("myReceivePlanList", result);
		return "/page/account/investlog/myreceiveplan.jsp";
	}
	/**
	 * <pre>
	 * 获取当前用户的回款日期列表
	 * </pre>
	 * @param request
	 * @param map
	 * @param area
	 * @param gameId
	 * @param printWriter
	 * @throws Exception
	 */
	@RequestMapping(value = "/getReceiveDay", method = RequestMethod.POST)
	@ResponseBody
	public void getReceiveDay (HttpServletRequest request, ModelMap map,String nowYear, String nowMonth,PrintWriter printWriter) throws Exception {
		UserInfo m = getSessionMember(request).getUser();
		List<String> dataList = serviceFactory.getRepaymentService().getReceiveDay(m.getId(), nowYear, nowMonth);
		Gson gson = new Gson();
		printWriter.write(gson.toJson(dataList));
        printWriter.flush();
        printWriter.close();
	}
}
